n,m = map(int,input().split())
lands = []
for _ in range(n):
    lands.append(list( map(int,input().split())))
    
row_prefix = [0]*m # 列的前缀和
col_prefix = [0]*n # 行的前缀和

for i in range(n):
    for j in range(m):
        row_prefix[j] += lands[i][j]
        col_prefix[i] += lands[i][j]

for i in range(1,m):
    row_prefix[i] += row_prefix[i-1]
for i in range(1,n):
    col_prefix[i] += col_prefix[i-1]
    
def SumRow(l,r):
    if l:
        return row_prefix[r]-row_prefix[l-1]
    return row_prefix[r]
    
def SumCol(l,r):
    if l:
        return col_prefix[r]-col_prefix[l-1]
    return col_prefix[r]

result = SumCol(0,n-1)
# 列切割
for i in range(1,m):
    result = min(result,abs(SumRow(0,i-1)-SumRow(i,m-1)))
# 行切割
for i in range(1,n):
    result = min(result,abs(SumCol(0,i-1)-SumCol(i,n-1)))

print(result)